package com.lanhe.admin.controller.order;

import com.lanhe.common.constant.Constants;
import com.lanhe.common.core.controller.BaseController;
import com.lanhe.common.core.domain.AjaxResult;
import com.lanhe.common.core.page.TableDataInfo;
import com.lanhe.order.domain.LhOrdersHaoka;
import com.lanhe.order.service.ILhOrdersHaokaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 号卡-订单
 *
 * @author zhanggl
 * @date 2023年12月25日22:32:59
 */
@RestController
@RequestMapping("/lhOrdersHaoka")
@Slf4j
public class LhOrdersHaokaController extends BaseController {

	@Resource
	private ILhOrdersHaokaService ordersHaokaService;


	/**
	 * 分页查询所有数据
	 */
	@PreAuthorize("@ss.hasPermi('order:lhOrdersHaoka:list')")
	@GetMapping("/list")
	public TableDataInfo list(LhOrdersHaoka ordersHaoka) {
		startPage();
		ordersHaoka.setIsRecharged("1");
		ordersHaoka.setIsActivated("1");
		List<LhOrdersHaoka> list = ordersHaokaService.selectOrdersList(ordersHaoka);
		for (LhOrdersHaoka lhOrdersHaoka : list) {
			lhOrdersHaoka.setStatusName(Constants.HaokaOrderStatus.getHaokaOrderStatusName(lhOrdersHaoka.getStatus()));
			lhOrdersHaoka.setAuditStatusName(Constants.HaokaOrderAuditStatus.getHaokaOrderAuditStatusName(lhOrdersHaoka.getAuditStatus()));
		}
		return getDataTable(list);
	}

	/**
	 * 根据ID查询订单
	 *
	 * @param orderId id
	 * @return com.lanhe.order.domain.LhOrdersHaoka
	 * @author zhanggl
	 * @date 2024年01月04日14:42:56
	 */
	@PreAuthorize("@ss.hasPermi('order:lhOrdersHaoka:query')")
	@GetMapping(value = {"/", "/{orderId}"})
	public AjaxResult getInfo(@PathVariable(value = "orderId") Long orderId) {
		LhOrdersHaoka lhOrdersHaoka = ordersHaokaService.selectOrdersHaokaById(orderId);
		lhOrdersHaoka.setStatusName(Constants.HaokaOrderStatus.getHaokaOrderStatusName(lhOrdersHaoka.getStatus()));
		lhOrdersHaoka.setAuditStatusName(Constants.HaokaOrderAuditStatus.getHaokaOrderAuditStatusName(lhOrdersHaoka.getAuditStatus()));
		return success(lhOrdersHaoka);
	}

	/**
	 * 审核
	 *
	 * @return com.lanhe.order.domain.LhOrdersHaoka
	 * @author zhanggl
	 * @date 2024年01月04日14:42:56
	 */
	@PreAuthorize("@ss.hasPermi('order:lhOrdersHaoka:audit')")
	@PostMapping("/audit")
	public AjaxResult audit(@RequestBody LhOrdersHaoka ordersHaoka) {
		if (ObjectUtils.isEmpty(ordersHaoka.getOrderId())){
			return error("主键ID不能为空");
		}
		return toAjax(ordersHaokaService.auditOrdersHaokaById(ordersHaoka));
	}

}

